function findPosition(num, xPos, yPos) {
    let rectSum = 0
    let whichRect = (Math.min(num - xPos - 1, xPos, yPos, num - yPos - 1))
        // for (let indexPos = 0; indexPos < whichRect; indexPos++) {
        //     let tempSum = num - indexPos - indexPos
        //     rectSum = (rectSum + tempSum * 4 - 4) % 9
        // }
    rectSum = (4 * whichRect % 9 * ((num - whichRect) % 9)) % 9
    xPos = xPos - whichRect
    yPos = yPos - whichRect
    let tempSum = num - (whichRect) * 2
    console.log(tempSum, whichRect, xPos, yPos, rectSum)

    if (xPos === 0) {
        return (rectSum + yPos + 1) % 9 === 0 ? 9 : (rectSum + yPos + 1) % 9
    } else if (yPos === 0) {
        return (rectSum + tempSum * 4 - 3 - xPos) % 9 === 0 ? 9 : (rectSum + tempSum * 4 - 3 - xPos) % 9
    } else if (yPos + 1 === tempSum) {
        return (rectSum + tempSum + xPos) % 9 === 0 ? 9 : (rectSum + tempSum + xPos) % 9
    } else {
        return (rectSum + tempSum * 3 - 3 - yPos + 1) % 9 === 0 ? 9 : (rectSum + tempSum * 3 - 3 - yPos + 1) % 9
    }
}

console.log(findPosition(702533400, 336774581, 230291515))